package cn.just.textCookier;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author wujiaming
 */
@WebServlet(name = "CookieServlet",value = "/CookieServlet")
public class CookieServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //创建cookie对象,并保存数据
        Cookie cookie = new Cookie("msg", "hellowprld");


        //把cookie下发到客户端
        response.addCookie(cookie);
        //页面实现添加完成
        response.setContentType("text/html;charset=utf-8");
        PrintWriter pw = response.getWriter();
        pw.print("添加完成");
        pw.close();
    }
}
